<?php

use app\models\Mall;
use yii\helpers\Url;

$web = Url::base();
$institution_code=Mall::getCurrentInstitutionCode();
//单位
$integral_unit = Mall::getCurrentInstitutionIntegralUnit();
//比率
$integral_rate = Mall::getCurrentInstitutionIntegralRate();
//是否可以混合支付
$is_cash_order = Mall::getCurrentInstitutionIsCashOrder();
//调试
$is_cash_order = $institution_code=='JG000001'? 1 :0;
$site_name = Mall::getCurrentInstitutionSiteName();


$this->title = $site_name . '-订单详情';

//是否有跨境电商商品
$is_crossborder=false;
$order_goods_count=0;
foreach($orderGoodsList as $item) {
    if($item['is_crossborder']=='1'){
        $is_crossborder=true;
    }
    $order_goods_count=$order_goods_count+ $item['quantity'] ;
}
?>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall/order-details.css"/>



<div class="order">
    <div class="order-state">
        <p class="fl">订单编号：<span><?=$orderInfo['code']?></span></p>
        <div class="clfl"></div>
        <div class="wait">
            <p class="fl wait-order"><?=$orderInfo['orderStatusTxt']?><span style="display: none;">（我们会尽快发货，请耐心等待）</span></p>
        </div>
    </div>

    <div class="information">
        <p>收货地址：<span><?=$orderInfo['receiver_name']?>，<?=$orderInfo['receiver_phone']?>，<?=$orderInfo['receiver_province']?><?=$orderInfo['receiver_city']?><?=$orderInfo['receiver_region']?><?=$orderInfo['receiver_address']?> </span></p>
        <!--<p>邮政编码：<span>400000</span></p>-->
        <p>下单时间：<span><?=$orderInfo['create_datetime']?></span></p>
    </div>
    <?php
        if(count($orderDeliveryList)>0){
    ?>
            <div class="tail-after" >
                <p class="title">物流状态</p>
                <div class="logistics">
                    <?php
                    foreach($orderDeliveryList as $item){
                    ?>
                        <div class="logistics-1">
                            <a class="logistics-link" onclick="loadDeliveryList(this,'<?=$item['logistics_code']?>')">
                                <img class="logistics-icon" src="<?= $web ?>/images/mall/logistics-icon.png" />
                                <div class="logistics-massage">
                                    <p>快件已经发货/物流公司：<?=$item['logistics_company']?></p>
                                    <p>运单编号：<?=$item['logistics_code']?></p>
                                    <p class="time"><?=date('Y-m-d h:i:s',strtotime($item['create_datetime']))?></p>
                                </div>
                                <img class="alink-icon" src="<?= $web ?>/images/mall/alink-icon.png" />
                                <div class="goods">
                                    <ul>
                                        <?php
                                        foreach($item['goods_list'] as $item2){
                                        ?>
                                            <li><img src="<?=$item2['image_url']?>@100w" /></li>
                                        <?php
                                        }
                                        ?>

                                    </ul>
                                </div>
                            </a>
                            <div class="content"  style="display: none;">

                            </div>
                        </div>
                    <?php
                    }
                    ?>

                   <!-- <div class="logistics-1">
                        <a class="logistics-link">
                            <img class="logistics-icon" src="imgs/logistics-icon.png" />
                            <div class="logistics-massage">
                                <p>快件已经发货/物流公司：顺丰速运</p>
                                <p>运单编号：888888888477</p>
                                <p class="time">2016-09-20 16:39:00</p>
                            </div>
                            <img class="alink-icon" src="imgs/alink-icon.png" />
                            <div class="goods">
                                <ul>
                                    <li><img src="imgs/goods.jpg" /></li>
                                    <li><img src="imgs/goods.jpg" /></li>
                                    <li><img src="imgs/goods.jpg" /></li>
                                    <li><img src="imgs/goods.jpg" /></li>

                                </ul>
                            </div>
                        </a>
                        <div class="content" style="display: none;">
                            <div class="message-last">
                                <div class="guide-line-last"></div>
                                <div class="contener">
                                    <img class="current-img" src="imgs/logistics-cur-img.png" />
                                    <p class="location">快件在【成都】已经装车，准备发往【成都双流集散中心】发往重庆</p>
                                    <p class="timer">2016-09-20 16:39:00</p>
                                </div>

                            </div>

                            <div class="message-center">
                                <div class="guide-line-center"></div>
                                <div class="contener">
                                    <img class="logistics-img" src="imgs/logistics-img.png" />
                                    <p class="location">快件在【成都】已经装车，准备发往【成都双流集散中心】发往重庆</p>
                                    <p class="timer">2016-09-20 16:39:00</p>
                                </div>
                            </div>

                            <div class="message-center">
                                <div class="guide-line-center"></div>
                                <div class="contener">
                                    <img class="logistics-img" src="imgs/logistics-img.png" />
                                    <p class="location">快件在【成都】已经装车，准备发往【成都双流集散中心】发往重庆</p>
                                    <p class="timer">2016-09-20 16:39:00</p>
                                </div>
                            </div>

                            <div class="message-first">
                                <div class="guide-line-first"></div>
                                <div class="contener">
                                    <img class="logistics-img" src="imgs/logistics-img.png" />
                                    <p class="location">物流状态已收取快件</p>
                                    <p class="timer">2016-09-20 16:39:00</p>
                                </div>
                            </div>
                        </div>
                    </div>-->
                </div>
            </div>
            <script type="text/javascript">
                function loadDeliveryList(me,logistics_code) {
                    var dom=$(me).siblings(".tail-after .content");
                    if(dom.is(':visible')){
                        dom.hide();
                        $(me).find(".alink-icon").removeClass("alink-icon-1");
                    }else{
                        if(dom.html()._trim()=='') {
                            var data = {};
                            data.logistics_code = logistics_code;
                            waittingShow('获取物流信息....');
                            requestHtml("delivery-detail-part-view", data, true, function (responsehtml) {
                                dom.html(responsehtml);
                                waittingHide();
                            });

                        }
                        dom.show();
                        $(me).find(".alink-icon").addClass("alink-icon-1");
                    }


                }
//                $(function() {
//                    var i = 0;
//                    $(".logistics-link").click(function() {
//                        if(i == 0) {
//                            $(this).siblings(".tail-after .content").show();
//                            $(this).find(".alink-icon").addClass("alink-icon-1");
//                            i = 1;
//                        } else if(i == 1) {
//                            $(this).siblings(".tail-after .content").hide();
//                            $(this).find(".alink-icon").removeClass("alink-icon-1");
//                            i = 0;
//                        }
//
//                    });
//                    $("#focus").focus();
//                });
            </script>
    <?php
        }
    ?>

</div>
<div class="list">
    <div class="repertoire">
        <p class="title">产品明细</p>
        <p class="sort"><span class="wares">共<a>（<?=$order_goods_count?>）</a>件商品 </span>
            <span>单价</span>
            <span>数量</span>
            <?php
            if($orderInfo['status']=='1'){
            ?>
                <span>库存</span>
            <?php
            }
            ?>

            <span>小计</span>
            <span>运费</span></p>
    </div>
    <div class="article">
        <?php
        $sum_integral=0;
        foreach($orderGoodsList as $item){
            $sum_integral=$sum_integral+($item['selling_integral'] * $item['quantity']);
        ?>
            <div class="listing">
                <div class="goods-img fl">
                    <a href="goods-detail?goods_code=<?= $item['goods_code'] ?>&institution_code=<?=$institution_code?>">
                        <img src="<?= $item['quantity']==0 ? $web.'/images/mall-m/goods-off-shelves.png':  $item['image_url'].'@120w' ?>"/>
                    </a>
                </div>
                <div class="goods-name fl">
                    <p>
                        <?php
                        if($item['is_crossborder']=='1'){
                            ?>
                            <span class="cross-title-icon">跨境</span>
                            <?php
                        }
                        ?>
                        <?= $item['goods_name'] ?>
                    </p>
                </div>
                <div class="statistics">
                    <ul>
                        <li><?= intval($item['selling_integral'])?><?=$integral_unit?></li>
                        <li><?= $item['quantity'] ?></li>
                        <?php
                            if($orderInfo['status']=='1'){
                        ?>
                                <li><?=$item['stock']?></li>
                        <?php
                            }
                        ?>

                        <li><?= $item['quantity'] * intval($item['selling_integral'])?><?=$integral_unit?></li>
                        <li>0.00</li>
                    </ul>
                </div>
            </div>
        <?php
        }
        ?>

        <!--<div class="listing">
            <div class="goods-img fl">
                <a href=""><img src="imgs/wares1.png" /></a>
            </div>
            <div class="goods-name fl">
                <p>多功能书籍平板两用折叠支架书籍平板两用折叠支架 </p>
            </div>
            <div class="statistics">
                <ul>
                    <li>289.9</li>
                    <li>1</li>
                    <li>-20.00</li>
                    <li>289.9</li>
                    <li>0.00</li>
                </ul>
            </div>
        </div>-->

    </div>
    <?php
    if($is_crossborder==true){
    ?>
        <div class="cross-border">

            <p class="cross-border-title">跨境保税商品购买须知</p>
            <div class="cross-border-content">
                <p class="s-title">跨境保税商品购买须知</p>
                <div class="content-1">
                    <p>一、什么是跨境保税商品<br/>跨境保税商品是采购自国外的商品，进境时海关、国检都会对商品的品质做审查（品质保证），进境后存放于保税区仓库，国内消费者通过电子商务平台下单购买后，在海关全程监管下打包出区，最终交由国内快递送至消费者手上。优点：商品进境时海关、国检对商品审查，商品存放保税仓库（绝无假货，品质保证）</p>
                </div>
                <div class="content-1">
                    <p>二、购买跨境保税商品要求<br /> 1、单笔订单不超过<span>2000元人民币</span>；
                        <br /> 2、每人次一年不能购买超过2万元人民币跨境保税商品（按身份证号计算）；
                        <br /> 3、根据中国海关总署要求，您所购买的商品需提供<span>身份证信息</span>进行入境申报，请您配合。我们不会向第三方泄露您的资料，请您放心。
                    </p>
                </div>
                <div class="content-1">
                    <p>三、跨境商品物流配送<br /> 跨境产品由于海关检验的特殊性，物流送达时间一般时效为：
                        <br /> 保税区邮：
                        <br /> 保税区—圆通，时效<span>5-7天</span>
                        <br /> 香港直邮：
                        <br /> 香港外包仓—申通快递，时效<span>10天左右</span>
                        <br /> 香港汇通仓—汇通快递，时效<span>8-10天</span>
                        <br /> 香港—圆通，时效<span>10-12天</span>
                        <br /> 海外直邮：
                        <br /> 日本直邮—EMS，时效<span>5-7天</span>
                        <br /> 日本—国际段联邦国内转邮政小包或韵达，时效<span>10-13天</span>
                        <br /> 荷兰—中欧快运，时效<span>10-15天</span>
                    </p>
                </div>
                <div class="content-1">
                    <p>
                        <span class="big-red">温馨提示：</span><br /> 由于海关系统升级于<span>16年12月30日18:00</span>后兑换的跨境产品，需要<span>17年1月10日</span>开始发货，给您带来的不变敬请谅解。
                    </p>
                </div>
            </div>

        </div>
    <?php
    }
    ?>

    <div class="total">
        <?php
        if($orderInfo['status']=='1'){
        ?>
            <p class="fr add-integral">共计<?=$integral_unit?><span class="integral"><?=$sum_integral?></span></p>
            <p class="fr">合计运费<span>0.00</span></p>
        <?php
            $pay_integral=$sum_integral;
            if($is_cash_order=='1' && $pay_integral>$userIntegral ) {
                $pay_integral = $userIntegral;
                $pay_cash = round(($sum_integral - $pay_integral) / $integral_rate, 2);
        ?>
            <script>
                var pay_cash=<?=$pay_cash?>;
            </script>
                <p class="fr">需付现金<span><?=$pay_cash?>￥</span></p>
                <p class="fr">需付<?=$integral_unit?><span><?=$pay_integral?></span></p>
        <?php
            }else{
        ?>
                <p class="fr">需付<?=$integral_unit?><span><?=$pay_integral?></span></p>
        <?php
            }
        ?>
        <?php
        }else{
            $sum_pay_integral=$orderInfo['integral'];
            if($orderInfo['cash_total_fee']){
                $sum_pay_integral=$sum_pay_integral-$orderInfo['cash_integral'];
            }
        ?>
            <p class="fr  add-integral">共计<?=$integral_unit?><span class="integral"><?=intval($orderInfo['integral'])?></span></p>
        <?php
            $pay_cash=0;
            if($orderInfo['cash_total_fee']) {
                $pay_cash = $orderInfo['cash_total_fee'] / 100;
        ?>
                <p class="fr">实付现金<span>￥<?=$pay_cash?></span></p>
        <?php
            }
        ?>
            <p class="fr">实付<?=$integral_unit?><span><?=intval($sum_pay_integral)?></span></p>
            <p class="fr">合计运费<span>0.00</span></p>
            <p class="fr">商品<?=$integral_unit?><span><?=intval($orderInfo['integral'])?></span></p>
        <?php
        }
        ?>

    </div>
    <div class="payment-btn">
    <?php
if($orderInfo['status']=='1'){
    if($all_stock_status=='1') {
    ?>
        <a href="javascript:payExec()" class="order-btn">确认支付</a>
    <?php
    }else{
    ?>
        <a href="javascript:void(0)" class="off-btn">没有库存</a>
    <?php
    }
    ?>
        <a href="javascript:cancelOrder()" class="off-btn">取消订单</a>
        <script>
            cancelOrder=function(){
                if(confirm("是否确认取消订单?")){
                    var data={};
                    data.order_code="<?=$orderInfo['code']?>";
                    data.remark='用户取消订单';
                    var re=requestJsonMallM('cancel-order-handle',data);
                    if(re.status==0) {
                        alert(re.message);
                        window.location.reload();
                    }else{
                        alert(re.message);
                    }
                }
            };
        </script>
    <?php
}
    ?>
    </div>
</div>
<script>
    var is_cash_order =<?=$is_cash_order?>;
    var cash_integral=0;

    payExec=function(){
        if(confirm("是否确认支付订单?")){
            waittingShow('等待支付完成');
            var data={};
            data.orderId="<?=$orderInfo['id']?>";
            var re=requestJsonMallM('pay-order-handle',data,true,function(re){
                if(re.status==0) {
                    var payOrderResult = re.data.payOrderResult;
                    if(payOrderResult.status=='0'){
                        // alert('支付订单成功');
                        window.location.href ="<?=Url::to(['mall/pay-order-success','institution_code'=>Mall::getCurrentInstitutionCode()])?>"+'&orderId='+payOrderResult.orderId;
                    }else{
                        if(payOrderResult.status=='20' && is_cash_order=='1'){
                            waittingHide();
                            //提示是否开始混合支付
                            var cash_integral = payOrderResult.cash_integral;
                            invokeCashPay(cash_integral,pay_cash,"<?=$orderInfo['code']?>",false,false,false);
                            return;
                        }
                        alert(payOrderResult.message);
                    }

                }else {
                    alert(re.message);
                }
                waittingHide();
            });

        }

    };

</script>
<?=\app\widgets\MallPayCash::widget([])?>
<?=\app\widgets\MallWaitting::widget([])?>